{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "72d3dfe4",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    ">0. 代码的注释\n",
    ">1. 用户输入\n",
    ">2. 格式化输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c43624c",
   "metadata": {},
   "source": [
    "## 代码的注释\n",
    ">1. “#” 一般写在代码块最上面，或者每一行代码的最后，用于代码思路记录\n",
    ">2. \"注释内容\"，一般是注释代码块内容\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5126e9da",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "## 1.引入列表概念\n",
    "网二 = [1,2,3,4,5]\n",
    "print(网二,type(网二))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0df9c433",
   "metadata": {},
   "source": [
    "## 用户输入\n",
    "> 1. input()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "53e8da22",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "username:kenny.l\n",
      "password:lzylove123.\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统\n",
    "username = input(\"username:\") \n",
    "password = input(\"password:\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2a07001b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'kenny.l'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "username"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "bba06f4a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "username:kenny.l\n",
      "password:lzylove123.\n",
      "欢迎kenny.l登陆成功\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 完善 1.增加判断功能\n",
    "# 假设我们数据库有用户信息：账号是kenny.l 密码是来自于lzylove123.\n",
    "user1 = \"kenny.l\"\n",
    "password1 = \"lzylove123.\"\n",
    "\n",
    "username = input(\"username:\") \n",
    "password = input(\"password:\")\n",
    "\n",
    "#情景一： 输入信息正确，登陆成功\n",
    "if user1 == username and password1 == password:\n",
    "    print(\"欢迎\"+user1+\"登陆成功\")\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "# 情景二：账号不存在或密码不正确\n",
    "else:\n",
    "    print(\"账号不存在或密码不正确\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "95e9937f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "username:jih\n",
      "password:jihjp\n",
      "账号不存在或密码不正确\n",
      "您还有2次2尝试的机会\n",
      "username:jij\n",
      "password:jijfg\n",
      "账号不存在或密码不正确\n",
      "您还有1次2尝试的机会\n",
      "username:jkfijf\n",
      "password:kfiof\n",
      "三次输入失败，请一小时后再来尝试\n"
     ]
    }
   ],
   "source": [
    "# 登陆系统 完善 2.增加循环功能\n",
    "# 假设我们数据库有用户信息：账号是kenny.l 密码是来自于lzylove123.\n",
    "user1 = \"kenny.l\"\n",
    "password1 = \"lzylove123.\"\n",
    "\n",
    "for i in range(3,0,-1):   # i 是一个int\n",
    "    username = input(\"username:\") \n",
    "    password = input(\"password:\")\n",
    "\n",
    "    #情景一： 输入信息正确，登陆成功\n",
    "    if user1 == username and password1 == password:\n",
    "        print(\"欢迎\"+user1+\"登陆成功\")\n",
    "        break # 终止循环\n",
    "    # 情景二：账号不存在或密码不正确\n",
    "    else:\n",
    "        if i == 1:\n",
    "            print(\"三次输入失败，请一小时后再来尝试\")\n",
    "        else:\n",
    "            print(\"账号不存在或密码不正确\")\n",
    "            print(\"您还有\"+str(i-1)+\"次2尝试的机会\") # str强制将int转换成str"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1be04a66",
   "metadata": {},
   "source": [
    "## 格式化输出"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d1bf102d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：lzy\n",
      "年龄：19\n",
      "工作：student\n",
      "收入：1w\n",
      "------INFO OF lzy------\n",
      "姓名：lzy\n",
      "年龄：19\n",
      "工作：student\n",
      "收入：1w\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "\n",
    "info = '''------INFO OF '''+ name + '''------'''+'''\n",
    "姓名：'''+name+'''\n",
    "年龄：'''+age+'''\n",
    "工作：'''+job+'''\n",
    "收入：'''+salary\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "b721f261",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：lzy\n",
      "年龄：18\n",
      "工作：学生\n",
      "收入：1w\n",
      "-----INFO OF lzy------\n",
      "年龄：18\n",
      "工作：学生\n",
      "收入：1w\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法二： 占位符 %s,依次有序输入\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "\n",
    "info = '''-----INFO OF %s------\n",
    "年龄：%s\n",
    "工作：%s\n",
    "收入：%s'''%(name,age,job,salary)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "0070d41d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "姓名：lzy\n",
      "年龄：18\n",
      "工作：学生\n",
      "收入：1w\n",
      "-----INFO OF %s------\n",
      "姓名：lzy\n",
      "年龄：18\n",
      "工作：学生\n",
      "收入：1w\n"
     ]
    }
   ],
   "source": [
    "# 用户注册系统 方法三：format() 格式化输出函数\n",
    "name = input(\"姓名：\")\n",
    "age = input(\"年龄：\")\n",
    "job = input(\"工作：\")\n",
    "salary = input(\"收入：\")\n",
    "\n",
    "info = '''-----INFO OF %s------\n",
    "姓名：{姓名}\n",
    "年龄：{年龄}\n",
    "工作：{工作}\n",
    "收入：{收入}'''.format(年龄 = age,姓名 = name,工作 = job,收入 = salary,)\n",
    "\n",
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e279198c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
